package com.xxg.renrenuser.service;

import com.xxg.renrencommon.domain.result.BaseResult;
import com.xxg.renrenuser.dao.*;
import com.xxg.renrenuser.domain.result.RenrenShopProfileResult;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

/**
 * 类说明
 *
 * @author szj
 * @date 2021/12/24
 */
@Service
@Slf4j
@AllArgsConstructor
public class UserServiceImpl implements UserService{
    private final RenrenShopUserProfileDao renrenShopUserProfileDao;
    private final RenrenShopShopProfileDao renrenShopShopProfileDao;
    private final RenrenShopShopDao renrenShopShopDao;
    private final static String ERROR_SHOP_ID = "-1";

    @Override
    public BaseResult<RenrenShopProfileResult> getUserProfile(String shopId, String userId) {
        RenrenShopProfileResult renrenShopProfileResult = new RenrenShopProfileResult();
        if (shopId != null && !ERROR_SHOP_ID.equals(shopId)) {
            RenrenShopShop renrenShopShop = renrenShopShopDao.selectByPrimaryKey(Integer.parseInt(shopId));
            RenrenShopShopProfile renrenShopShopProfile = renrenShopShopProfileDao.selectByPrimaryKey(Integer.parseInt(shopId));
            BeanUtils.copyProperties(renrenShopShopProfile, renrenShopProfileResult);
            renrenShopProfileResult.setName(renrenShopShop.getName());
            renrenShopProfileResult.setLogo(renrenShopShop.getLogo());
            return new BaseResult<>(renrenShopProfileResult);
        }
        RenrenShopUserProfile renrenShopUserProfile = renrenShopUserProfileDao.selectByPrimaryKey(Integer.parseInt(userId));
        renrenShopProfileResult.setName(renrenShopUserProfile.getNickname());
        renrenShopProfileResult.setLogo(renrenShopUserProfile.getAvatar());
        return new BaseResult<>(renrenShopProfileResult);
    }
}
